<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<h2 id="time"></h2>

<body>
  
  <script>
    function counter() {
      var date = new Date();
      var year = date.getFullYear();
      var m = date.getMonth();
      var d = date.getDate();
      var date2 = new Date(year, m, d, 23, 59, 59);
      var time = (date2 - date) / 1000;
      var day = Math.floor(time / (24 * 60 * 60))
      var hour = Math.floor(time % (24 * 60 * 60) / (60 * 60))
      var minute = Math.floor(time % (24 * 60 * 60) % (60 * 60) / 60);
      var second = Math.floor(time % (24 * 60 * 60) % (60 * 60) % 60);
      var str ="今天还剩" + day + "天" + hour + "时" + minute + "分" + second + "秒";
      document.getElementById("time").innerText = str;
    }
    window.setInterval("counter()", 1000);
    
  </script>
</body>

</html>